<style lang="less">
.show-data{
  text-align:center;
  .tip{
    line-height:60px;
  }
  .rotate{
    transform:rotate(180deg)
  }
}
.data-box{
  height:170px;
  overflow:hidden;
  .dp-container{
    transform: translateY(-45px) !important;
  }
}
</style>
<template>
<div class="show-data">
  <p class="tip">—— 请选择日期 ——</p>
  <div class="data-box data1">
    <datetime-view v-model="value1"
      year-row="{value}年" month-row="{value}月" day-row="{value}日" :end-date='endDate'></datetime-view></div>
  <div><i class="iconfont icon-traggle"></i></div>
  <div>至</div>
  <div class="rotate"><i class="iconfont icon-traggle"></i></div>
  <div class="data-box data2">
    <datetime-view v-model="value2"
      year-row="{value}年" month-row="{value}月" day-row="{value}日" :end-date='endDate'></datetime-view></div>
  <div class="btn-bottom"><div class="btn" @click="sure">确定</div></div>
</div>
</template>

<script>
  export default{
    data(){
      return{
        value1:'',
        value2:''
      }
    },
    computed:{
      endDate(){
        return this.getCurrentDate();
      }
    },
    created(){
      this.value1 = this.getCurrentDate();
      this.value2 = this.getCurrentDate();
    },
    methods:{
      sure(){
        var _this = this;
        var d1 = new Date(_this.value1.replace(/\-/g, "\/"));  
        var d2 = new Date(_this.value2.replace(/\-/g, "\/"));
        if(_this.value1!="" && _this.value2!="" && d1 > d2)  
        {  
          _this.$vux.toast.show({
            type:'warn',//success, warn, cancel, text
            text: "起始日期不能大于结束日期",
          });
          return false;  
        }

        _this.$router.push({
          path:'/user/settlement',
          query:{d1:_this.value1,d2:_this.value2}
        });
      },
      getCurrentDate(){
        var date = new Date();
        var spl = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + spl + month + spl + strDate;
        return currentdate;
      },
    }
  }
</script>